/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Logic;

import Graphics.FieldGraphics;
import HelperClasses.GlobalFunctions;
import Player.Player;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.TreeSet;

/**
 *
 * @author johannes
 */
public class Result {

    public static int getPoints(Player player, ArrayList<Stone> stones) {
        // Steine nach Spieler getrennt in ein SortedSet packen
//        Sorted
        TreeSet<Double> playerStones = new TreeSet<Double>();
        TreeSet<Double> opponentStones = new TreeSet<Double>();
        for (Stone s : stones) {
            if (s.isInGame()) {
                if (s.getOwner() == player) {
                    playerStones.add(GlobalFunctions.pointDistance(s.getPos(), FieldGraphics.houseCenter));
                } else {
                    opponentStones.add(GlobalFunctions.pointDistance(s.getPos(), FieldGraphics.houseCenter));
                }
            }
        }

        // Vergleich
        int res = 0;
        Double minOpp = 40.0 + FieldGraphics.stoneSize / 2; // Nur Steine im House zählen
        if (opponentStones.size() > 0) {
            minOpp = Math.min(minOpp, opponentStones.first());
        }
        for (Double dist : playerStones) {
            if (minOpp > dist) {
                res++;
            } else {
                break;
            }
        }

        return res;
    }
}
